package com.docMan.action;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.lucene.queryparser.classic.ParseException;
import org.apache.lucene.search.highlight.InvalidTokenOffsetsException;
import org.apache.struts2.ServletActionContext;
import org.hibernate.Query;
import org.springframework.beans.factory.annotation.Autowired;

import com.docMan.bean.DirectoryMakeRunnable;
import com.docMan.bean.IndexFile;
import com.docMan.bean.Page;
import com.docMan.bean.PageDangan;
import com.docMan.bean.PageLucene;
import com.docMan.dao.pojo.Dangan;
import com.docMan.dao.pojo.DocBook;
import com.docMan.dao.pojo.DocBookSon;
import com.docMan.dao.pojo.DocDirectory;
import com.docMan.dao.pojo.DocDisc;
import com.docMan.dao.pojo.DocFile;
import com.docMan.dao.pojo.DocFtp;
import com.docMan.dao.pojo.DocType;
import com.docMan.lucene.Searcher;
import com.docMan.service.DangAnFromOaService;
import com.docMan.service.DocBookService;
import com.docMan.service.DocBookSonService;
import com.docMan.service.DocDirectoryService;
import com.docMan.service.DocDiscService;
import com.docMan.service.DocFileService;
import com.docMan.service.DocRecordService;
import com.docMan.service.DocTypeService;
import com.docMan.utils.CastUtil;
import com.docMan.utils.FileMoveService;
import com.docMan.utils.FileTypeUtil;
import com.docMan.utils.FinalConfig;
import com.docMan.utils.FtpUtils;
import com.docMan.utils.GetRealPath;
import com.docMan.utils.OpenOfficeUtil;
import com.docMan.utils.PoiUtils;
import com.docMan.utils.ProjectUtils;
import com.docMan.utils.Tif2Pdf;
import com.docMan.utils.Word2Html;
import com.opensymphony.xwork2.Action;
import com.docMan.service.DocForwardService;
import com.itextpdf.text.pdf.PdfStructTreeController.returnType;

public class IndexAction extends BaseAction {
	private List<DocDisc> docDiscs;
	private List<DocDirectory> docDirectories;
	private List<DocFile> docFiles;
	private DocDiscService docDiscService;
	private DocFileService docFileService;
	private DocDirectoryService docDirectoryService;
	private int diskId;
	private int directoryId;
	private File oafile;
	private String oafileFileName;
	private String oaFilepath;
	private Map<String, Object> dataMap = new HashMap<String, Object>();
	private int fileId;
	private String param;
	private List<IndexFile> indexFiles;
	private String previewText;
	private HttpSession session;
	private DocRecordService docRecordService;
	private List<DocDirectory> pathDirectories = new ArrayList<>();
	private DocDisc docDisc;
	private String poiFileHtmlPath = "view\\poihtml\\";
	private String previewUrl = "";
	private PageLucene pageLucene = new PageLucene();
	private String indexFrom = "0";
	private FileMoveService fileMoveService = FileMoveService.getInstance();
	private InputStream previewStream;
	private String previewFileName;
	private DocForwardService docForwardService;
	private DocTypeService docTypeService;
	private Page<Dangan> pageDangan=new Page<Dangan>();
	
	public Page<Dangan> getPageDangan() {
		return pageDangan;
	}
	public void setPageDangan(Page<Dangan> pageDangan) {
		this.pageDangan = pageDangan;
	}
	@Autowired
	public void setDocTypeService(DocTypeService docTypeService) {
		this.docTypeService = docTypeService;
	}
	@Autowired
	public void setDocForwardService(DocForwardService docForwardService) {
		this.docForwardService = docForwardService;
	}
	public String getPreviewFileName() {
		return previewFileName;
	}

	public void setPreviewFileName(String previewFileName) {
		this.previewFileName = previewFileName;
	}

	public InputStream getPreviewStream() {
		return previewStream;
	}

	public void setPreviewStream(InputStream previewStream) {
		this.previewStream = previewStream;
	}

	public String getIndexFrom() {
		return indexFrom;
	}

	public void setIndexFrom(String indexFrom) {
		this.indexFrom = indexFrom;
	}

	public PageLucene getPageLucene() {
		return pageLucene;
	}

	public void setPageLucene(PageLucene pageLucene) {
		this.pageLucene = pageLucene;
	}

	public String getPreviewUrl() {
		return previewUrl;
	}

	public void setPreviewUrl(String previewUrl) {
		this.previewUrl = previewUrl;
	}

	@Resource
	public void setDocRecordService(DocRecordService docRecordService) {
		this.docRecordService = docRecordService;
	}

	@Autowired
	public void setSession(HttpSession session) {
		this.session = session;
	}

	@Resource
	public void setDocFileService(DocFileService docFileService) {
		this.docFileService = docFileService;
	}

	@Resource
	public void setDocDirectoryService(DocDirectoryService docDirectoryService) {
		this.docDirectoryService = docDirectoryService;
	}

	@Resource(name = "docDiscService")
	public void setDocDiscService(DocDiscService docDiscService) {
		this.docDiscService = docDiscService;
	}

	public String index() {

		docDiscs = docDiscService.find("select d from DocDisc d");
		return Action.SUCCESS;
	}

	public String searchIndex() {
		List<DocDirectory> dirs = docDirectoryService
				.find("select dir from DocDirectory dir where dir.personalDisk=1 and dir.humanId=?",
						CastUtil.castInt(session
								.getAttribute(FinalConfig.SESSION_HUMANID)));
		if (dirs.size() != 0) {
			session.setAttribute(FinalConfig.PersonalDirId, dirs.get(0).getId());
		}
		return Action.SUCCESS;
	}
	
	public String searchIndexNoLogin() {
		List<DocDirectory> dirs = docDirectoryService
				.find("select dir from DocDirectory dir where dir.personalDisk=1 and dir.humanId=?",
						CastUtil.castInt(session
								.getAttribute(FinalConfig.SESSION_HUMANID)));
		if (dirs.size() != 0) {
			session.setAttribute(FinalConfig.PersonalDirId, dirs.get(0).getId());
		}
		return Action.SUCCESS;
	}
	public String pageSearchLuceneNoLogin() {

		Searcher searcher;
		try {
			searcher = new Searcher(FinalConfig.index_dir,session);
			// pageLucene.setCurrentPage(currentPage);
			pageLucene.init();
			if(!pageLucene.getIsPage()){
				pageLucene.setCurrentPage(1);
			}
			// pageLucene = searcher.pageBooleanSearch(pageLucene);
			pageLucene = searcher.newPageBooleanSearch(pageLucene);
			// pageLucene=searcher.searchHighlighter(pageLucene);
			searcher.close();
		} catch (Exception e) {
			e.printStackTrace();
			return Action.ERROR;
		}
		return Action.SUCCESS;
	}
	public String fileView() {
		if (diskId > 0) {
			// docDirectories=docDirectoryService.find("select d from DocDirectory d where d.diskId=?",diskId);
			docDirectories = docDirectoryService
					.findHumanSeeableDirInDisk(diskId);
			docFiles = docFileService.find(
					"select f from DocFile f where f.diskId=?", diskId);
			docDisc = docDiscService.getById(diskId);
		}
		return "success";
	}

	public String directoryView() {
		if (directoryId > 0) {
			// docDirectories=docDirectoryService.find("select d from DocDirectory d where d.directoryId=?",directoryId);
			docDirectories = docDirectoryService
					.findHUmanSeeableDirInDirectory(directoryId);
			docFiles = docFileService.find(
					"select f from DocFile f where f.directoryId=?",
					directoryId);
			DocDirectory docDirectory = docDirectoryService
					.getById(directoryId);
			pathDirectories = docDirectoryService.getPathDirectory(directoryId);
			pathDirectories.add(docDirectory);
			int forwardCount=(int) docForwardService.count("select count(*) from DocForward f where f.toHumanId=?", CastUtil.castInt(session
					.getAttribute(FinalConfig.SESSION_HUMANID)));
			session.setAttribute("forwardCount", forwardCount);
		}
		return "success";
	}

	public String searchLucene() {
		Searcher searcher;
		try {
			searcher = new Searcher(FinalConfig.index_dir,session);
			indexFiles = searcher.searchHighlighter("fileName", param);
			searcher.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return "error";
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return "error";
		} catch (InvalidTokenOffsetsException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return "error";
		}
		return "success";
	}

	public String pageSearchLucene() {

		Searcher searcher;
		try {
			searcher = new Searcher(FinalConfig.index_dir,session);
			// pageLucene.setCurrentPage(currentPage);
			pageLucene.init();
			if(!pageLucene.getIsPage()){
				pageLucene.setCurrentPage(1);
			}
			// pageLucene = searcher.pageBooleanSearch(pageLucene);
			pageLucene = searcher.newPageBooleanSearch(pageLucene);
			// pageLucene=searcher.searchHighlighter(pageLucene);
			searcher.close();
		} catch (Exception e) {
			e.printStackTrace();
			return Action.ERROR;
		}
		return Action.SUCCESS;
	}
	
	public String docPreview() {
		if (fileId > 0) {
			if (indexFrom.equals(FinalConfig.INDEX_FORM_UPLOAD)) {
				try {
					DocFile docFile = docFileService.getById(fileId);
					String realPath = GetRealPath.getPath(docFile.getPath());
					Random random1=new Random(10000);
					Random random2=new Random(10000);
					String localPath = FinalConfig
							.getFtpDownloadLocalPath(random1.nextInt(10000)+random2.nextInt(10000));// 这里应该是session中的humanid
					System.out.println("下载成功"+FtpUtils.downloadFile(FinalConfig.getDocFtp(),
							docFile.getFileName(), realPath, localPath));
					File file = new File(localPath + docFile.getFileName());
					System.out.println(realPath);
					System.out.println(localPath);
					System.out.println("fileId"+fileId);
					if (FileTypeUtil.fileType(docFile.getFileName()).equals(
							FileTypeUtil.file_pdf)||FileTypeUtil.fileType(docFile.getFileName()).equals(
									FileTypeUtil.file_tif)) {
						System.out.println(docFile.getFileName());
						if(FileTypeUtil.fileType(docFile.getFileName()).equals(
								FileTypeUtil.file_pdf)){
							System.out.println("pdfpdfpdf");
							previewStream=new FileInputStream(file);
							previewFileName=URLEncoder.encode(docFile.getFileName(), "UTF-8");
							System.out.println("pdf:"+file.getCanonicalPath());
							return "pdfReview";
						}else if(FileTypeUtil.fileType(docFile.getFileName()).equals(
								FileTypeUtil.file_tif)){
							System.out.println("tiftif");
							previewFileName=docFile.getFileName().replace("tiff", "pdf").replace("tif", "pdf");
							Tif2Pdf.convert(localPath+docFile.getFileName(), localPath+previewFileName);
							previewStream=new FileInputStream(new File(localPath+previewFileName));
							return "pdfReview";
						}
					}else if (FileTypeUtil.fileType(docFile.getFileName()).equals(
							FileTypeUtil.file_excel)||FileTypeUtil.fileType(docFile.getFileName()).equals(
									FileTypeUtil.file_word)) {
						System.out.println("word文件");
						
						String word2pdfFilePaht=localPath+docFile.getFileName().replace(".docx", ".pdf").replace(".doc", ".pdf");
						System.out.println(word2pdfFilePaht);
						try {
							OpenOfficeUtil.office2PDF(file.getCanonicalPath(), word2pdfFilePaht);
							file=new File(word2pdfFilePaht);
							previewStream=new FileInputStream(file);
							previewFileName=URLEncoder.encode(docFile.getFileName().replace(".docx", ".pdf").replace(".doc", ".pdf"), "UTF-8");
							return "pdfReview";
						} catch (IOException e) {
							e.printStackTrace();
						}
						/*String outPutFileHtml = ProjectUtils
								.getProject(FinalConfig.POI_OFFICE2HTML_PATH);
						previewUrl = PoiUtils.convert2Html(file, docFile.getId()
								.toString());
						String code = ProjectUtils.codeString(outPutFileHtml
								+ docFile.getId() + ".html");
						ServletActionContext.getResponse().setCharacterEncoding(
								code);
						previewText = PoiUtils.getFileContent(file);
						if (previewText.equals("")) {
							previewText = "该文件暂时不支持预览";
						} else {
							docRecordService.record(fileId,
									FinalConfig.FILE_PREVIEW);
						}*/
					}
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			} else if (indexFrom.equals(FinalConfig.INDEX_FORM_OA)) {
				return "oaDocPreview";
			}
		}
		System.out.println("1111");
		return "success";
	}

	public String myFiles() {
		/*List<DocDisc> tempdocDiscs = docDiscService.find(
				"select disk from DocDisc disk where disk.unitId=?",
				CastUtil.castInt(session
						.getAttribute(FinalConfig.SESSION_HUMAN_UNIT_ID)));
		// TODO 这里其实不用判断该部门的文件夹是否创建，因为一般情况下都是创建好的
		docDisc = tempdocDiscs.get(0);
		List<DocDirectory> personalDirectories = docDirectoryService
				.find("select dir from DocDirectory dir where dir.personalDisk=1 and dir.name=?",
						CastUtil.castString(session
								.getAttribute(FinalConfig.SESSION_HUMANNAME)));
		DocDirectory personalDisk = null;
		if (personalDirectories.size() == 0) {
			personalDisk = new DocDirectory();
			personalDisk.setName(CastUtil.castString(session
					.getAttribute(FinalConfig.SESSION_HUMANNAME)));
			personalDisk.setDiskId(docDisc.getId());
			personalDisk.setHumanName(CastUtil.castString(session
					.getAttribute(FinalConfig.SESSION_HUMANNAME)));
			personalDisk.setPath(docDisc.getId().toString());
			personalDisk.setUnitId(CastUtil.castInt(session
					.getAttribute(FinalConfig.SESSION_HUMAN_UNIT_ID)));
			personalDisk.setReName(CastUtil.castString(session
					.getAttribute(FinalConfig.SESSION_HUMANNAME)));
			// 默认情况下，个人网盘的顶级文件夹可见范围是全局可见，然后再此后面的文件夹的可见性默认是个人可见的
			personalDisk.setDisplayRange(FinalConfig.DirectoryDisplayRange_ALL);
			personalDisk.setPersonalDisk(FinalConfig.PersonalDiskDir);
			docDirectoryService.saveOrUpdateDirectory(personalDisk, null);
		} else {
			personalDisk = personalDirectories.get(0);
		}*/
		DocDirectory personalDisk=docDirectoryService.createPersonalDirectory();
		docDirectories = docDirectoryService.find(
				"select dir from DocDirectory dir where dir.directoryId=?",
				personalDisk.getId());
		docFiles = docFileService.find(
				"select file from DocFile file where file.directoryId=?",
				personalDisk.getId());
		pathDirectories = docDirectoryService.getPathDirectory(personalDisk
				.getId());
		pathDirectories.add(personalDisk);
		directoryId = personalDisk.getId();
		return Action.SUCCESS;
	}
	/**
	 * 政策法规
	 * @return
	 */
	public String zcfg() {
		return Action.SUCCESS;
	}
	
	/**
	 * 重要文件
	 * @return
	 */
	public String zywj(){
		
		return Action.SUCCESS;
	}
	public String zywjNoLogin(){
		return Action.SUCCESS;
	}
	public String zywjSearch(){
		Searcher searcher;
		try {
			/*searcher = new Searcher(FinalConfig.index_dir,session);
			if(!pageLucene.getIsPage()){
				pageLucene.setCurrentPage(1);
			}
			if(pageLucene.getLwdw().equals("宁波市政府集合")){
				
			}
			pageLucene = searcher.newPageBooleanSearch(pageLucene);
			searcher.close();*/
			Query query=null;
			if(pageDangan.getSearchText().equals("")){
				query=dangAnFromOaService.getQuery("select da from Dangan da where da.vlwdw=? and da.important=? order by da.vlastdate desc");
				query.setParameter(0, pageDangan.getLwdw());
				query.setParameter(1, "是");
			}else{
				query=dangAnFromOaService.getQuery("select da from Dangan da where  da.vlwbt like ? and da.vlwdw=? and da.important=?  order by da.vlastdate desc");
				query.setParameter(1, pageDangan.getLwdw());
				query.setParameter(2, "是");
				System.out.println(pageDangan.getSearchText());
				query.setParameter(0, '%'+pageDangan.getSearchText()+'%');
			}
			pageDangan=dangAnFromOaService.newPage(pageDangan,query);
		} catch (Exception e) {
			e.printStackTrace();
			return Action.ERROR;
		}
		return Action.SUCCESS;
	}
	
	public String zywjSearchNoLogin(){
		return zywjSearch();
	}
	
	/**
	 * 公文浏览
	 * @return
	 */
	public String gwll(){
		return Action.SUCCESS;
	}
	private Page<Dangan> danganPage=new Page<Dangan>();
	private String nd="";
	private String gwllSearchType;
	private boolean isQtSearch=false;
	private DangAnFromOaService dangAnFromOaService;
	private String qtLwdw="其他";
	private boolean isqtlwdw=false;
	public String gwllSearch(){
		danganPage=dangAnFromOaService.queryPage(danganPage, nd, gwllSearchType,isQtSearch,isqtlwdw,qtLwdw);
		return Action.SUCCESS;
	}
	private DocBookService docBookService;
	private List<DocBook> docBooks=new ArrayList<DocBook>(); 
	private Page<DocBook> bookPage=new Page<DocBook>();
	private int bookId=0;
	private DocBookSonService docBookSonService;
	private Page<DocBookSon> bookSonPage=new Page<DocBookSon>();
	private int bookSonId=0;
	private String bookPicFtpPre="";
	private boolean isFather=false;
	private List<DocType> docTypes=null;
	private int typeId=0;
	private String bookSonTile=null;
	private boolean searchByBookSonTitle=false;
	public String docType(){
		docTypes=docTypeService.find("select doc from DocType doc order by doc.createTime");
		return Action.SUCCESS;
	}
	
	public String book(){
		if((boolean) session.getAttribute(FinalConfig.is_admin)){
			DocFtp docFtp=FinalConfig.getDocFtp();
			bookPicFtpPre="ftp://"+docFtp.getIp()+":"+docFtp.getPort()+docFtp.getDiskName().trim()+"/book/";
//			bookPage=docBookService.restPage("select book from  DocBook book where book.bookTypeId="+typeId +" order by book.orderId", bookPage);
			bookPage=docBookService.restPage("select book from  DocBook book  order by book.orderId", bookPage);
			return Action.SUCCESS;
		}else {
			return Action.ERROR;
		}
	}
	public String bookSonFather(){
		bookSonPage.setEveryPage(10);
		bookSonPage=docBookSonService.restPage("select bookSon from DocBookSon bookSon where bookSon.isDirectory=0"
				+ " and bookSon.fatherBookId="+bookId +" order by bookSon.createTime desc ", bookSonPage);
		return Action.SUCCESS;
	}
		
	public String bookSonFatherView(){
		if(searchByBookSonTitle){
			bookSonPage=docBookSonService.restPage("select bookSon from DocBookSon bookSon where bookSon.isDirectory=0"
					+ " and bookSon.subTitle like '%"+bookSonTile+"%' order by bookSon.createTime desc ", bookSonPage);
		}else{
			bookSonPage=docBookSonService.restPage("select bookSon from DocBookSon bookSon where bookSon.isDirectory=0"
					+ " and bookSon.fatherBookId="+bookId +" order by bookSon.createTime  ", bookSonPage);
		}
		return Action.SUCCESS;
	}
	
	public String bookSon(){
		if(bookId!=0){
			String hqlString="select bookSon from DocBookSon bookSon where bookSon.isDirectory=1 and "
					+ " bookSon.fatherBookId="+bookId +" order by bookSon.orderId ";
			bookSonPage=docBookSonService.restPageNoCache(hqlString, bookSonPage);
		}
		return Action.SUCCESS;
	}
	public String bookSonNView(){
		bookSonPage.setEveryPage(10);
		if(searchByBookSonTitle){
			bookSonPage=docBookSonService.restPage("select bookSon from DocBookSon bookSon where  bookSon.isDirectory=0 "
					+ "and bookSon.subTitle like '%"+bookSonTile+"%' order by bookSon.createTime desc", bookSonPage);
		}else{
			bookSonPage=docBookSonService.restPage("select bookSon from DocBookSon bookSon where  bookSon.isDirectory=0 "
					+ "and bookSon.bookSonId="
					+bookSonId +" order by bookSon.createTime ", bookSonPage);
		}
		
		return Action.SUCCESS;
	}
	public String bookSonNEditView(){
		bookSonPage.setEveryPage(10);
		bookSonPage=docBookSonService.restPage("select bookSon from DocBookSon bookSon where bookSon.isDirectory=0 and  bookSon.bookSonId="+bookSonId +" order by bookSon.createTime desc", bookSonPage);
		return Action.SUCCESS;
	}
	
	public String bookSonN(){
		bookPage=docBookService.restPage("select book from DocBook book order by book.orderId", bookPage);
		/*if(bookId!=0){
			bookSonPage=docBookSonService.restPage("select bookSon from DocBookSon bookSon where bookSon.fatherBookId="+bookId +" order by bookSon.orderId ", bookSonPage);
		}*/
		return Action.SUCCESS;
	}
	public String bookSonNEdit(){
		bookPage=docBookService.restPage("select book from DocBook book order by book.orderId ", bookPage);
		/*if(bookId!=0){
			bookSonPage=docBookSonService.restPage("select bookSon from DocBookSon bookSon where bookSon.fatherBookId="+bookId +" order by bookSon.orderId ", bookSonPage);
		}*/
		return Action.SUCCESS;
	}
	
	public String officeFilePreview(){
		DocBookSon docBookSon=docBookSonService.getById(bookSonId);
		DocBook docBook=docBookService.getById(bookId);
		String fileType=null;
		if(isFather){
			fileType="pdf";
		}else {
			
			if(docBookSon.getIsUploadFile().equals(0)){
				previewUrl="/webService/show/DocBookSon/getBookSon/"+bookSonId;
				return "pdf";
			}
			fileType=FileTypeUtil.fileType(docBookSon.getDisplayName());
		}
		if(fileType.equals(
				FileTypeUtil.file_excel)||fileType.equals(
						FileTypeUtil.file_word)){
//			String localPath=FinalConfig.getFtpDownloadLocalPath(session.getAttribute(FinalConfig.SESSION_HUMANID));
			Random random1=new Random(10000);
			Random random2=new Random(10000);
			String localPath = FinalConfig
					.getFtpDownloadLocalPath(random1.nextInt(10000)+random2.nextInt(10000));// 这里应该是session中的humanid
			String remotePath="/book/"+docBookSon.getId();
			FtpUtils.downloadFile(FinalConfig.getDocFtp(), docBookSon.getDisplayName(), remotePath, localPath);
			try {
//				previewUrl=PoiUtils.convert2Html(file, docBookSon.getId().toString());
				if(isFather){
					previewUrl="/webService/show/DocBookService/getBook/"+bookId;
				}else {
					previewUrl="/webService/show/DocBookSon/getBookSon/"+bookSonId;
				}
				return "pdf";
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}else {
			if(isFather){
				previewUrl="/webService/show/DocBookService/getBook/"+bookId;
			}else {
				previewUrl="/webService/show/DocBookSon/getBookSon/"+bookSonId;
			}
			return "pdf";
		}
		return SUCCESS;
	}
	
	public String knowledge(){
		docDirectories=docDirectoryService.knowledgeDirectories();
		return Action.SUCCESS; 
	}
	public String knowledgeSub(){
		docDirectories=docDirectoryService.knowledgeDirectoriesSub(directoryId);
		return Action.SUCCESS;
	}
	/**
	 * 异步上传文件
	 */
	public void asynUpload() {
		String filePathDate = ProjectUtils
				.date2String("yyyy-MM-dd", new Date());
		String path = FinalConfig.STRUTS_UPLOAD_PATH + filePathDate + "/"
				+ System.currentTimeMillis() + "/";
		File file = new File(path, oafileFileName);
		if (!file.getParentFile().exists()) {
			file.getParentFile().mkdirs();
		}
		InputStream in;
		try {
			in = new FileInputStream(oafile);
			OutputStream out = new FileOutputStream(file);
			byte[] buffer = new byte[1024 * 1024 * 2];
			int length;
			while ((length = in.read(buffer)) > 0) {
				out.write(buffer, 0, length);
			}
			in.close();
			out.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
		oaFilepath = file.getAbsolutePath();
		dataMap.put("filePath", oaFilepath);
		write(dataMap);
	}
	
	
	public boolean getSearchByBookSonTitle() {
		return searchByBookSonTitle;
	}
	public void setSearchByBookSonTitle(boolean searchByBookSonTitle) {
		this.searchByBookSonTitle = searchByBookSonTitle;
	}
	public String getBookSonTile() {
		return bookSonTile;
	}
	public void setBookSonTile(String bookSonTile) {
		this.bookSonTile = bookSonTile;
	}
	public int getTypeId() {
		return typeId;
	}
	public void setTypeId(int typeId) {
		this.typeId = typeId;
	}
	public List<DocType> getDocTypes() {
		return docTypes;
	}
	public void setDocTypes(List<DocType> docTypes) {
		this.docTypes = docTypes;
	}
	public boolean getIsFather() {
		return isFather;
	}
	public void setIsFather(boolean isFather) {
		this.isFather = isFather;
	}
	public String getBookPicFtpPre() {
		return bookPicFtpPre;
	}
	public void setBookPicFtpPre(String bookPicFtpPre) {
		this.bookPicFtpPre = bookPicFtpPre;
	}
	public int getBookSonId() {
		return bookSonId;
	}
	public void setBookSonId(int bookSonId) {
		this.bookSonId = bookSonId;
	}
	public Page<DocBookSon> getBookSonPage() {
		return bookSonPage;
	}
	public void setBookSonPage(Page<DocBookSon> bookSonPage) {
		this.bookSonPage = bookSonPage;
	}
	@Autowired
	public void setDocBookSonService(DocBookSonService docBookSonService) {
		this.docBookSonService = docBookSonService;
	}
	public int getBookId() {
		return bookId;
	}
	public void setBookId(int bookId) {
		this.bookId = bookId;
	}
	public Page<DocBook> getBookPage() {
		return bookPage;
	}
	public void setBookPage(Page<DocBook> bookPage) {
		this.bookPage = bookPage;
	}
	public List<DocBook> getDocBooks() {
		return docBooks;
	}
	public void setDocBooks(List<DocBook> docBooks) {
		this.docBooks = docBooks;
	}
	@Autowired
	public void setDocBookService(DocBookService docBookService) {
		this.docBookService = docBookService;
	}
	public String getQtLwdw() {
		return qtLwdw;
	}

	public boolean getIsqtlwdw() {
		return isqtlwdw;
	}

	public void setIsqtlwdw(boolean isqtlwdw) {
		this.isqtlwdw = isqtlwdw;
	}

	public void setQtLwdw(String qtLwdw) {
		this.qtLwdw = qtLwdw;
	}

	public DangAnFromOaService getDangAnFromOaService() {
		return dangAnFromOaService;
	}
	
	public boolean getIsQtSearch() {
		return isQtSearch;
	}

	public void setIsQtSearch(boolean isQtSearch) {
		this.isQtSearch = isQtSearch;
	}

	@Autowired
	public void setDangAnFromOaService(DangAnFromOaService dangAnFromOaService) {
		this.dangAnFromOaService = dangAnFromOaService;
	}

	public String getNd() {
		return nd;
	}

	public void setNd(String nd) {
		this.nd = nd;
	}

	public String getGwllSearchType() {
		return gwllSearchType;
	}

	public void setGwllSearchType(String gwllSearchType) {
		this.gwllSearchType = gwllSearchType;
	}

	public Page<Dangan> getDanganPage() {
		return danganPage;
	}

	public void setDanganPage(Page<Dangan> danganPage) {
		this.danganPage = danganPage;
	}

	public String getPreviewText() {
		return previewText;
	}

	public void setPreviewText(String previewText) {
		this.previewText = previewText;
	}

	public int getFileId() {
		return fileId;
	}

	public void setFileId(int fileId) {
		this.fileId = fileId;
	}

	public String getParam() {
		return param;
	}

	public void setParam(String param) {
		this.param = param;
	}

	public List<IndexFile> getIndexFiles() {
		return indexFiles;
	}

	public void setIndexFiles(List<IndexFile> indexFiles) {
		this.indexFiles = indexFiles;
	}

	public int getDirectoryId() {
		return directoryId;
	}

	public void setDirectoryId(int directoryId) {
		this.directoryId = directoryId;
	}

	public File getOafile() {
		return oafile;
	}

	public void setOafile(File oafile) {
		this.oafile = oafile;
	}

	public String getOafileFileName() {
		return oafileFileName;
	}

	public void setOafileFileName(String oafileFileName) {
		this.oafileFileName = oafileFileName;
	}

	public String getOaFilepath() {
		return oaFilepath;
	}

	public void setOaFilepath(String oaFilepath) {
		this.oaFilepath = oaFilepath;
	}

	public Map<String, Object> getDataMap() {
		return dataMap;
	}

	public void setDataMap(Map<String, Object> dataMap) {
		this.dataMap = dataMap;
	}

	public List<DocDisc> getDocDiscs() {
		return docDiscs;
	}

	public void setDocDiscs(List<DocDisc> docDiscs) {
		this.docDiscs = docDiscs;
	}

	public List<DocDirectory> getDocDirectories() {
		return docDirectories;
	}

	public void setDocDirectories(List<DocDirectory> docDirectories) {
		this.docDirectories = docDirectories;
	}

	public List<DocFile> getDocFiles() {
		return docFiles;
	}

	public void setDocFiles(List<DocFile> docFiles) {
		this.docFiles = docFiles;
	}

	public int getDiskId() {
		return diskId;
	}

	public void setDiskId(int diskId) {
		this.diskId = diskId;
	}

	public List<DocDirectory> getPathDirectories() {
		return pathDirectories;
	}

	public void setPathDirectories(List<DocDirectory> pathDirectories) {
		this.pathDirectories = pathDirectories;
	}

	public DocDisc getDocDisc() {
		return docDisc;
	}

	public void setDocDisc(DocDisc docDisc) {
		this.docDisc = docDisc;
	}
	
	public String ssobookson(){
		
		return Action.SUCCESS;
	}
	
	public String ssobook(){
		
		return Action.SUCCESS;
	}
	
	public String ssogwll(){
		
		return Action.SUCCESS;
	}
	public String ssozywj(){
		return Action.SUCCESS;
	}
	public String ssoSearch(){
		return Action.SUCCESS;
	}
	public String ssoMyFile(){
		return Action.SUCCESS;
	}
	public String ssozcfg(){
		return Action.SUCCESS;
	}
}
